<#-- @ftlvariable name="table" type="com.baomidou.mybatisplus.generator.config.po.TableInfo" -->
package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import com.bidanet.bdcms.core.bean.AjaxCallBack;
import com.bidanet.bdcms.core.vo.Page;

import ${package.Entity}.${entity};
import ${package.Controller}.view.${entity}View;
import ${package.Controller}.view.${entity}AddView;
import ${package.Controller}.view.${entity}EditView;
import ${package.Service}.${table.serviceName};

/**
 * <p>
    * ${table.comment!} 前端控制器
    * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass}<${table.serviceName}> {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};


    @RequestMapping("/index")
    @ResponseBody
    public String index(${entity} queryVo, Page<${entity}> page) {
        baseService.queryLike(queryVo, page);
        ${entity}View listView = new ${entity}View(page, queryVo);
        return listView.toHtml();
    }

    @RequestMapping("/add")
    @ResponseBody
    public String add(${entity} addVo) {
        ${entity}AddView addView = new ${entity}AddView(addVo);
        return addView.toHtml();
    }

    @RequestMapping("add_save")
    @ResponseBody
    public AjaxCallBack addSave(${entity} addVo) {
        baseService.insert(addVo);
        return AjaxCallBack.saveSuccess();
    }

    @RequestMapping("/edit")
    @ResponseBody
    public String edit(Long id) {
        ${entity} editVo = baseService.get(id);
        ${entity}EditView editView = new ${entity}EditView(editVo);
        return editView.toHtml();
    }

    @RequestMapping("/edit_save")
    @ResponseBody
    public AjaxCallBack editSave(${entity} editVo) {
        baseService.update(editVo);
        return AjaxCallBack.saveSuccess();
    }

    @RequestMapping("/del")
    @ResponseBody
    public AjaxCallBack del(Long id) {
        baseService.del(id);
        return AjaxCallBack.handleSuccess();
    }
}
</#if>
